/**
 * 2017-06-20 23:57:43
 *
 **/


/**
 * 添加评论
 */
function addComment() {
    var text_node = document.getElementById("comment_text");
    var text = text_node.value;
    var book_id = parseInt(text_node.getAttribute("title"));
    ajax_Comment(book_id,text);
}


/**
 * 提交评论并显示
 */

function ajax_Comment(book_id,text) {
    var xmlhttp;

    if (window.XMLHttpRequest) {// code for IE7+, Firefox, Chrome, Opera, Safari
        xmlhttp = new XMLHttpRequest();
    } else {// code for IE6, IE5
        xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
    }

    xmlhttp.onreadystatechange = function () {
        if (xmlhttp.readyState == 4 && xmlhttp.status == 200) {
            var state = xmlhttp.responseText;
            if (state == 0){
                alert('评论失败!');
            }else if (state == 2){
                alert('请登陆后发表评论!');
            }else if (state == 3){
                alert('评论不得为空!');
            }else {
                location.reload();
                alert('评论成功!');
            }
        }
    }
    xmlhttp.open("GET", "server/add_comment.php?book_id="+book_id+"&text="+text, true);
    xmlhttp.send();

    // alert("Method!");
}
//
